<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>订单确认</title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />

    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/template/default/recouse/css/confirm.css?v=111" />
    <script type="text/javascript" src="https://static.9hive.cn/global/vendor/jquery/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="/res/js/jquery.lSelect.js"></script>
    <script type="text/javascript" src="/res/js/jquery.validate.js"></script>

    <!--微信支付-->
    <script type="text/javascript" src="/res/plugins/weixin/static/weui/lib/jquery-2.1.4.js"></script>
    <script type='text/javascript' src="/res/plugins/weixin/static/weui/js/jquery-weui.js"></script>
    <!-- layer -->
    <script src="/res/plugins/weixin/static/layer/layer.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
    <style>
        body{padding-bottom:55px}

        .label_radio input {
            margin-right: 5px;
        }

        .has-js .label_radio {
            padding-left: 26px;
        }

        .has-js .label_radio {
            background-position: 0 0;
            background: url(/template/default/recouse/images/radio_none.png) no-repeat;
            background-size: 16px 16px;
        }
        .has-js label.r_on {
            background-position: 0 0px;
            background: url(/template/default/recouse/images/radio_check.png) no-repeat;
            background-size: 16px 16px;
        }
        .has-js .label_radio input {
            position: absolute;
            left: -9999px;
        }

        .btn-danger {
            color: #ffffff;
            background-color: #d9534f;
            border-color: #d43f3a;
        }

        .btn {
            display: inline-block;
            padding: 6px 12px;
            margin-bottom: 0;
            font-size: 14px;
            font-weight: normal;
            line-height: 1.428571429;
            text-align: center;
            white-space: nowrap;
            vertical-align: middle;
            cursor: pointer;
            background-image: none;
            border: 1px solid transparent;
            border-radius: 4px;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            -o-user-select: none;
            user-select: none;
        }
    </style>

    <script type="text/javascript">
        /* 微信支付 */
        function wxpay(){
            $.showLoading("正在加载...");
            //测试时修改为自己的openId 如果不修改会出现【下单账号与支付账号不一致】的提示 这里最好授权获取
            var openId=$("input[name='openId']").val();
            var total_fee="${amountPayable + paymentFee}";//总费用
            var orderId=$("input[name='order.id']").val();
            var paymentConfigId=$("input[name='paymentConfig.id']").val();
            var amountPayable=$("input[name='amountPayable']").val();
            var paymentType=$("input[name='paymentType']").val();
            $.post("/b/payment/gateway",
                    {
                        "openId":openId,
                        "total_fee":total_fee,
                        "order.id":orderId,
                        "paymentConfig.id":paymentConfigId,
                        "amountPayable":amountPayable,
                        "paymentType":paymentType,
                        "shopId":'${shopId!}',
                    },
                    function(res){
                        $.hideLoading();
                        if (res.code == 0) {

                            var data=$.parseJSON(res.data);
                            if (typeof WeixinJSBridge == "undefined"){
                                if( document.addEventListener ){
                                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
                                }else if (document.attachEvent){
                                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
                                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
                                }
                            }else{
                                onBridgeReady(data);
                            }
                        }else{
                            if (res.code == 2) {
                                layer.alert(res.message) ;
                            }else{
                                layer.msg("参数错误："+res.message, {shift: 6});
                            }
                        }
                    });
        }
        function onBridgeReady(json){
            WeixinJSBridge.invoke(
                    'getBrandWCPayRequest',
                    json,
                    function(res){
                        // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                        if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                            layer.msg("支付成功", {shift: 6});
                            var orderId=$("input[name='order.id']").val();
                            window.location.href="/b/order/view?id="+orderId+"&shopId=${shopId}";
                        }else{
                            layer.msg("支付失败", {shift: 6});
                        }
                    }
            );
        }

    </script>

</head>
<body style="min-width: 320px;max-width: 640px;margin:0 auto;background: white">
<div class="infobox ">
    <form action="/b/payment/gateway" method="post">
        <input type="hidden" name="shopId" value="${shopId!}"/>
        <input type="hidden" name="paymentType" value="${paymentType!}" />
        <input type="hidden" name="amountPayable" value="${amountPayable!}" />
        <input type="hidden" name="paymentConfig.id" value="${paymentConfig.id!}" />
        <input type="hidden" name="order.id" value="${order.id!}" />
        <input type="hidden" name="openId" value="${openId!}"/>
        <input type="hidden" name="shopId" value="${shopId!}" />
        <br/>
        <p>
            尊敬的<strong class="" style="color: green">${loginMember.username}</strong>，<br/><br/>
            您选择的支付方式为：<strong>${paymentConfig.name}</strong>
            <!--<%if (order! != null){%><a href="/b/order/view?id=${order.id}">[查看订单详情]</a><%}%>-->
        </p>
        <br/>
        <p>
            支付总金额：<strong class="red">${(amountPayable + paymentFee),orderUnitCurrencyFormat}</strong>
            <%if (paymentConfig.paymentFeeTypeValue == "scale" && paymentConfig.paymentFee != 0){%>
            [含支付手续费费率：${paymentConfig.paymentFee}%]
            <%}else if (paymentConfig.paymentFeeTypeValue == "fixed" && paymentConfig.paymentFee != 0){%>
            [含支付手续费：${paymentConfig.paymentFee,orderUnitCurrencyFormat}]
            <%}%>
        </p>
        <br/>
        <div class="buttonArea">
            <!--如果是微信支付,用post提交-->
            <%if(paymentConfig.paymentConfigTypeValue=="weixin"){%>
            <button type="button" id='submit'  name="submit" onclick="wxpay();" style="display: inline-block;float: right;padding: 0 33px;text-align: center;height: 35px;line-height: 35px;margin-right: 10px;color: #fff;background: #e4393c;font-size: 16px;border: none;border-radius: 5px;">确认支付</button><p></p>
            <%}else{%>
            <button type="submit" id='submit'  name="submit" value="yes" style="display: inline-block;float: right;padding: 0 33px;text-align: center;height: 35px;line-height: 35px;margin-right: 10px;color: #fff;background: #e4393c;font-size: 16px;border: none;border-radius: 5px;">确认支付</button><p></p>
            <%}%>
        </div>
    </form>

</div>

<script src="/template/default/recouse/js/zepto.min.js" type="text/javascript"></script>
</body>
</html>